angular.module('liemallfodder')
  .controller('HomeCtrl', function ($scope, Loading, ApiManager, MaterialApi) {

    $scope.categories = {};
    $scope.banners = {};

    $scope.onReadySwiper = function (swiper) {
      swiper.initObservers();
    };

    var requestListCategory = function () {
      Loading.show('正在加载');
      MaterialApi.listCategory(function (result) {
        Loading.hide();
        if (ApiManager.hasError(result)) {
          return;
        }
        $scope.categories = result.data;

      }, function (error) {
        Loading.hide();
        ApiManager.showError(error);
      });
    };

    $scope.showBlank = true;
    var requestListBanner = function () {
      MaterialApi.listBanner(function (result) {
        if (ApiManager.hasError(result)) {
          return;
        }
        $scope.banners = result.data;
        $scope.showBlank = isEmptyObj($scope.banners);

      }, function (error) {
        ApiManager.showError(error);
      });
    };

    var isEmptyObj = function (e) {
      var t;
      for (t in e)
        return !1;
      return !0;
    };

    requestListCategory();
    requestListBanner();
  });
